<?php

App::uses('FrontController', 'Controller');

class ModulesController extends FrontController {

    public $name = 'Modules';
    public $uses = array('Content');

    public function posturl() {
        $this->set('title_for_layout', 'Suggest New Url');
        if(!empty($this->data)) {
            $data = $this->data;
            $cats = unserialize(Cache::read("maincat", "5year"));
            $url_tofind = substr($data['Content']['suggest_url'],1,strlen($data['Content']['suggest_url']));
            $idx_cat = array_search($url_tofind, $cats);
            $data['Content']['category_id'] = $idx_cat;
            if(strpos($data['Content']['url'],'http://') === false && strpos($data['Content']['url'],'https://') === false) {
                $data['Content']['url'] = 'http://'.$data['Content']['url'];
            }
            $result = $this->Content->save($data);
            if(isset($result['Content']['id'])) {
                // save successful
                $this->redirect('/post-url-success');
            }
        }
    }
    public function posturlsuccess() {
        $this->set('title_for_layout', 'New Url Submitted');
    }
}